<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>课程表</title>
    <script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
    <link href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/5.0.2/css/bootstrap.min.css" rel="stylesheet">
</head>
<style>
    form table tr th {
        text-align: right;
    }

    form table tr td {
        text-align: left;
    }
</style>

<body>
    <div style="text-align: right;">
        <a href="/"><button>购物车</button></a>
        <br><br>
    </div>
    <div style="text-align: center;width: 400px;">
        <form action="/add" method="post">
            <table class="table table-hover">
                <tr>
                    <th>上课日期：</th>
                    <td><input type="date" name="1.1" value="" /><input type="time" name="1.2" value="" /></td>
                </tr>
                <tr>
                    <th>上课节数：</th>
                    <td><input type="number" name="2" value="" placeholder="" min="1" max="4" /></td>
                </tr>
                <tr>
                    <th>上课地点：</th>
                    <td><input type="text" name="3" value="" /></td>
                </tr>
                <tr>
                    <th>课程名称：</th>
                    <td><input type="text" name="4" value="" /></td>
                </tr>
            </table>
            <div style="text-align: center;">
                <input type="submit" name="10" value=" 添加课程 " />
            </div>
        </form>
    </div><br>
    <hr>
    <div style="text-align: center;">
        <table class="table table-hover">
            <tr>
                <th>课程名</th>
                <th>上课时间</th>
                <th>上课节数</th>
                <th>上课地点</th>
                <th>操作</th>
            </tr>
            {%for course in courses%}
            <tr>
                <td>{{course.course_name}}</td>
                <td>{{course.course_time}}</td>
                <td>{{course.course_num}}</td>
                <td>{{course.classroom}}</td>
                <td><a href="/del?id={{course.id}}">删除</a></td>
            </tr>
            {% endfor %}
        </table>
    </div>
    {%if ts!=''%}
    <script>alert('{{ts}}'); window.location.href = '/course';</script>
    {%else%}
    <script>
        function sleep(ms) {
            return new Promise(resolve => setTimeout(resolve, ms));
        }

        async function chixuqingqiu() {
            while (true) {
                const d = await get15();
                //console.log(d);
                if (d == 'wait') {
                    await sleep(15000);
                }
                else {
                    alert(d);
                    break;
                }
                await sleep(1000);
            }
        }


        async function get15() {
            var t = '9';
            await $.post('/get15').done(function (data) {
                t = data.ts;
            });
            return t;
        }

        chixuqingqiu();
    </script>
    {%endif%}
</body>